import adminConfig from '@/admin.config.js'
export default {
  namespaced: true,
  state: {
    siteStatus: 1,
    siteName: "",
    siteLogo: "",
    siteIcp: "",
  },
  getters: {},
  mutations: {},
  actions: {
    list(_, data) {
      return uni.request({
        url: '/unify/config/index',
        data
      })
    },
    form(_, data = {}) {
      return uni.request({
        url: '/unify/config/form',
        data
      })
    },
    save(_, data = {}) {
      return uni.request({
        url: `/unify/config/${data.id?'update':'save'}`,
        data
      })
    },
    setValues(_, data) {
      return uni.request({
        url: '/unify/config/setValues',
        data
      })
    },
    read(_, data) {
      return uni.request({
        url: '/unify/config/read',
        data
      })
    },
    delete(_, data) {
      return uni.request({
        url: '/unify/config/delete',
        data
      })
    },
    copyright(_, data) {
      return uni.request({
        url: '/unify/config/copyright',
        data
      })
    },
    backgroundInit(_, data) {
      return uni.request({
        url: '/unify/config/backgroundInit',
        data
      })
    },
    updateField(_, data) {
      return uni.request({
        url: `/unify/config/updateField`,
        data
      })
    },
    init({
      state,
      dispatch
    }, data) {
      uni.request({
        url: '/unify/config/initConfig'
      }).then(data => {
        state.siteIcp = data.base_site_icp;
        state.siteLogo = data.base_site_logo;
        state.siteName = data.base_site_name;
        state.siteStatus = data.base_site_status;

        if (!parseInt(state.siteStatus)) {
          uni.showModal({
            title: "提示",
            content:"服务暂停，请联系服务员",
            success() {
              dispatch('init')
            },
            showCancel: false
          })
        }
      })
    }
  }
}